//
//  XSAllListViewController.m
//  XSDataBaseDemo
//
//  Created by 大帅 on 2023/12/19.
//

#import "XSAllListViewController.h"

#import "XSAllListTableViewCell.h"

// cell标识符
static NSString *allListTableViewCellId = @"XSAllListTableViewCellId";

@interface XSAllListViewController () <UITableViewDelegate, UITableViewDataSource>
/** 列表视图 */
@property (nonatomic, strong) UITableView *tableView;
/** 数据 */
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation XSAllListViewController

-(NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"查";
    self.view.backgroundColor = [UIColor.orangeColor colorWithAlphaComponent:1];
    
    NSArray *arr = [[XSDataSaveManager sharedManager] lookDownloadAllData];
    [self.dataArray addObjectsFromArray:arr];
    
    [self createViewUI];
    
}

-(void)createViewUI {
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.top.mas_equalTo(GK_STATUSBAR_NAVBAR_HEIGHT);
    }];
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc] init];
        if (@available(iOS 11.0,*)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
        [_tableView registerClass:[XSAllListTableViewCell class] forCellReuseIdentifier:allListTableViewCellId];
    }
    return _tableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 65;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XSAllListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:allListTableViewCellId forIndexPath:indexPath];
    if (self.dataArray.count > indexPath.row) {
        cell.model = [self.dataArray objectAtIndex:indexPath.row];
    }
    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
